class Solution {
public:
    int pivotIndex(vector<int>& nums) {
        int n = nums.size();
        vector<int> qianzhui(n);
        qianzhui[0] = nums[0];
        vector<int> houzhui(n);
        houzhui[n - 1] = nums[n - 1];
        for (int i = 1, j = n - 2; i < n && j >= 0; i++, j--)
        {
            qianzhui[i] += qianzhui[i - 1] + nums[i];
            houzhui[j] += houzhui[j + 1] + nums[j];
        }
        // for(int i = 0;i<n;i++)
        // {
        //     cout<<qianzhui[i]<<" "<<houzhui[i]<<endl;
        // }
        for (int i = 0; i < n; i++)
        {
            if (qianzhui[i] == houzhui[i])
            {
                return i;
            }
        }

        return -1;
    }
};